package net.oschina.spider;

import com.mchange.v2.lang.StringUtils;
import net.oschina.task.Task;

/**
 * Created by rex on 2015/3/9.
 */
public class Main {
    public static void main(String[] args) {
        if (args.length > 0){
            if (args[0].equals("get")){
                if (args[1].equals("username")) {
                    String location = "";
                    System.out.println("[i] we will get the user of " + args[2]);
                    if(args.length > 2){
                        location = args[2];
                    }else{
                        location = "China";
                    }

                    String attach = "";
                    if (args.length > 3){
                        attach = args[3];
                    }else {
                        attach = "";
                    }

                    Task.list(location, attach);
                }else if(args[1].equals("email")){
                    Task.getEmail();

                    if(args.length > 2){
                        if(args[2].equals("patch")){
                            Task.getEmailPatch();
                        }
                    }
                }else{
                    invalidArg();
                }
            }else if (args[0].equals("send")){
//                System.out.println("mail sending...");
                String configPath = System. getProperty ("user.dir")+System.getProperty("file.separator")+"mail.properties";
                System. out .println("user.dir path: " + configPath);
                Task.sendMail(configPath);
            }else if (args[0].equals("howmany")){
                String location = "";

                if (args.length > 1){
                    location = args[1];
                }else {
                    location = "China";
                }
                System.out.println("[" + location + "]");
                System.out.println("Total: " + Task.getNum(location));
            }
        }else{
            System.out.println("Spider");
            System.out.println("Usage:");
            System.out.println("      spider get username location");
            System.out.println("      spider get email");
            System.out.println("      spider get email patch");
            System.out.println("      spider howmany location");
            System.out.println("      spider send");
        }

    }

    private static void invalidArg(){
        System.out.println("invalid arguments");
    }
}
